home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / Parse.l < prev    next >
Encoding:
Text File  |  1996-08-01  |  5.6 KB  |  228 lines

  1. /*                                                                              */
  2. /*   (C) COPYRIGHT International Business Machines Corp. 1993                   */
  3. /*   All Rights Reserved                                                        */
  4. /*   Licensed Materials - Property of IBM                                       */
  5. /*   US Government Users Restricted Rights - Use, duplication or                */
  6. /*   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.          */
  7.  
  8. /* definitions */
  9. digit    [0-9]
  10. char     [a-zA-Z_.]
  11. alphanum [0-9a-zA-Z_.\-\*]
  12. %{  /* code to be included */
  13. #ifdef WIN32
  14. #include <windows.h>
  15. #endif
  16. #include "Suite.h"
  17. #include "TestList.h"
  18. #include "AttrList.h"
  19. #include "PropList.h"
  20. #include "General.h"
  21. #include "Print.h"
  22. #include "TestName.h"
  23. #include "PropName.h"
  24. #include "NameList.h"
  25. #include "Global.h"
  26. #include "AttrName.h"
  27. #include "Table.h"
  28. #include <GL/gl.h>
  29. #include <GL/glu.h>
  30. #ifdef WIN32
  31. #include <gl\glaux.h>
  32. #endif
  33. #include "AttrTab.h"
  34. #include "PropTab.h"
  35. #include "TestTab.h"
  36. #if defined(__OS2__)
  37. #include "y_tab.h"
  38. #elif defined(WIN32)
  39. #include "ytab.h"
  40. #else
  41. #include "y.tab.h"
  42. #endif
  43. #include <stdlib.h>
  44. #include <malloc.h>
  45.  
  46. TablePtr attributes;
  47. TablePtr properties;
  48. TablePtr tests;
  49. int printMode = 0;
  50. #if defined(DEC)
  51. int yylineno = 1;
  52. #elif defined(WIN32)
  53. int visualID = -1;
  54. static int yylineno = 1;
  55. #endif
  56.  
  57. %}
  58. /* end of definitions */
  59. %%
  60. \{    return(openCurly);
  61. \}    return(closeCurly);
  62. \[    return(openBracket);
  63. \]    return(closeBracket);
  64. \(    return(openParen);
  65. \)    return(closeParen);
  66. "%"    return(Percent);
  67. ","    return(comma);
  68.  
  69. \/\*            {
  70.                 A:
  71.                 switch (input()) {
  72.                   case '*': goto B;
  73.                   case 0: printf("GLperf: EOF found before comment ended\n"); exit(1);
  74. #if defined(WIN32) || defined(DEC)
  75.                   case '\n': yylineno++;
  76. #endif
  77.                   default:  goto A;
  78.                 }
  79.                 B:
  80.                 switch (input()) {
  81.                   case '*': goto B;
  82.                   case '/': break;
  83.                   case 0: printf("GLperf: EOF found before comment ended\n"); exit(1);
  84. #if defined(WIN32) || defined(DEC)
  85.                   case '\n': yylineno++;
  86. #endif
  87.                   default:  goto A;
  88.                 }
  89.             }
  90.  
  91. \"            {
  92.                 int i;
  93.                 int n = 32;
  94.                 char* buffer = (char*)malloc(n);
  95.                 for (i=0; (buffer[i] = input()) != '"'; i++) {
  96. #if defined(WIN32) || defined(DEC)
  97.                 if (buffer[i] == '\n') yylineno++;
  98. #endif
  99.                 buffer = (i == n-2) ? (char*)realloc(buffer, n+=32) : buffer;
  100.                 }
  101.                 buffer[i] = (char)0;
  102.                 yylval.attr = new_Attribute_String(buffer);
  103.                 Attribute__SetLineNum(yylval.attr, yylineno);
  104.                 free(buffer);
  105.                 return(attrName);
  106.             }
  107.  
  108. \/\/            {
  109.                 char ch;
  110.                 while ((ch = input()) != '\n');
  111. #if defined(WIN32) || defined(DEC)
  112.                 if (ch == '\n') yylineno++;
  113. #endif
  114.             }
  115.  
  116. \*            {
  117.                 yylval.attr = new_Attribute_Int((int)WildCard);
  118.                 Attribute__SetLineNum(yylval.attr, yylineno);
  119.                 return(wildcard);
  120.             }
  121.  
  122. [Aa][Ll][Ll]        {
  123.                 yylval.attr = new_Attribute_Int((int)WildCard);
  124.                 Attribute__SetLineNum(yylval.attr, yylineno);
  125.                 return(wildcard);
  126.             }
  127.  
  128. [Ff][Rr][Oo][Mm]    return(From);
  129. [Tt][Oo]        return(To);
  130. [Ss][Tt][Ee][Pp]    return(step);
  131. [Pp][Rr][Ii][Nn][Tt][Ff]    return(Printf);
  132.  
  133. 0x[0-9A-Fa-f]+        {
  134.                 yylval.attr = new_Attribute_Int((int)strtol((const char*)yytext, NULL, 16));
  135.                 Attribute__SetLineNum(yylval.attr, yylineno);
  136.                 return(attrName);
  137.             }
  138.  
  139. [+-]?{digit}+         {
  140.                 yylval.attr = new_Attribute_Int((int)atoi((char*)yytext));
  141.                 Attribute__SetLineNum(yylval.attr, yylineno);
  142.                 return(attrName);
  143.             }
  144.  
  145. [+-]?[0-9]*"."[0-9]*([eE][+-][0-9]+)?    {
  146.                 yylval.attr = new_Attribute_Float((float)atof((char*)yytext));
  147.                 Attribute__SetLineNum(yylval.attr, yylineno);
  148.                 return(attrName);
  149.             }
  150.  
  151. {alphanum}*    {
  152.                 int i;
  153.                 FILE* fp;
  154.  
  155.                 if (Table__Lookup(tests, (char*)yytext, &i)) {
  156.                 yylval.ival = i;
  157.                 return(testName);
  158.                 } else if (Table__Lookup(properties, (char*)yytext, &i)) {
  159.                 yylval.attr = new_Attribute_Int((int)i);
  160.                     Attribute__SetLineNum(yylval.attr, yylineno);
  161.                 return(PropName);
  162.                 } else if (Table__Lookup(attributes, (char*)yytext, &i)) {
  163.                 yylval.attr = new_Attribute_Int((int)i);
  164.                     Attribute__SetLineNum(yylval.attr, yylineno);
  165.                 return(attrName);
  166.                             } else {
  167.                                 /* No error checking done here anymore */
  168.                 printf("GLperf: Line %d, Unidentifiable symbol \"%s\"\n",yylineno, (char*)yytext);
  169.                                 yylval.attr = new_Attribute_String((char*)yytext);
  170.                     Attribute__SetLineNum(yylval.attr, yylineno);
  171.                                 return(errorName);
  172.                             }
  173.             }
  174.  
  175. \r*\n           {
  176. #if defined(WIN32) || defined(DEC)
  177.             yylineno++;
  178. #endif
  179.         }
  180. [ \t]+        {}
  181. %%
  182. void yyinit(int argc, char** argv)
  183. {
  184.     int i;
  185.  
  186.     for (i=1; i<argc; i++) {
  187.         if (strcmp(argv[i],"-d")==0) {
  188.         printMode |= Delta;
  189.         } else if (strcmp(argv[i],"-s")==0) {
  190.         printMode |= StateDelta;
  191.         } else if (strcmp(argv[i],"-p")==0) {
  192.         printMode |= Pixels;
  193.         } else if (strcmp(argv[i],"-u")==0) {
  194.         printMode |= MicroSec;
  195.         } else {
  196.             yyin = fopen(argv[i], "r");
  197.             if (!yyin) {
  198.                 printf("GLperf: Cannot open input file: %s\n", argv[i]);
  199.                 exit(1);
  200.             }
  201.         }
  202.     }
  203.  
  204.     attributes = new_Table();
  205.     properties = new_Table();
  206.     tests      = new_Table();
  207.     Table__Load(attributes, Attributes, NumAttributes);
  208.     Table__Load(properties, Properties, NumProperties);
  209.     Table__Load(tests, Tests, NumTests);
  210. }
  211.  
  212. int
  213. yyclose(void)
  214. {
  215.     delete_Table(attributes);
  216.     delete_Table(properties);
  217.     delete_Table(tests);
  218.     auxCloseWindow();
  219.     return(0);
  220. }
  221.  
  222. #ifndef yywrap
  223. int yywrap(void)
  224. {
  225.   return(1);
  226. }
  227. #endif
  228.